package com.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

@Controller
public class WebSocketController {
    @Autowired
    private SimpMessagingTemplate template;
    //采用广播方式推送 5秒一次
    @Scheduled(fixedRate = 5000)
    public void sendTopicMessage() {
        System.out.println("后台广播推送！");
        this.template.convertAndSend("/topic/getResponse", "今天苏州的温度是18到25度");
    }
}
